Repository navigation
fix: Use the server's FDv1 fallback TTL from the header and goodbye - #278
Conversation
Co-Authored-By: Bee Klimt <bklimt@launchdarkly.com>
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
| return interrupted(errorInfo, fdv1Fallback, null, completionCallback); | ||
| } | ||
|
|
||
| public static FDv2SourceResult interrupted(DataSourceStatusProvider.ErrorInfo errorInfo, boolean fdv1Fallback, Duration fdv1FallbackTTL, Function<Void, Void> completionCallback) { |
There was a problem hiding this comment.
I think a more future-proof design might be to replace boolean fdv1Fallback, Duration fdv1FallbackTT with a new nullable FDv1Fallback object that contains a Duration ttl. That way, if the format changes in the future, we don't have to change all the interfaces.
There was a problem hiding this comment.
Done in 71beeaa. There's a new datasources.FDv1Fallback, holding a nullable Duration ttl. The FDv2SourceResult factories now take a nullable FDv1Fallback in place of the boolean, where null means no directive, so the extra TTL overloads are gone. getFdv1Fallback() returns the directive, and isFdv1Fallback() remains as a != null shorthand.
Co-Authored-By: Bee Klimt <bklimt@launchdarkly.com>
Co-Authored-By: Bee Klimt <bklimt@launchdarkly.com>
There was a problem hiding this comment.
Risk: medium.
Automated risk review (dry run): Medium
This PR would not be automatically approved. Human approval required.
Why: This changes FDv1 fallback TTL handling in the Java server SDK data source (FDv2DataSource, PollingBase, StreamingSynchronizerImpl, HeaderConstants, and experimental FDv2SourceResult/FDv1Fallback), a protocol-behavior change across polling, streaming, initializer, and synchronizer paths. Tests cover the new TTL rules, but the blast radius is more than a narrow low-risk edit.
Human review is needed and no reviewers were assigned.
If you disagree with this review, share this PR in #feedback-agent-approvals or submit a changes-requested review explaining why.
Sent by Cursor Approval Agent: Dry-Run PR Approver
| @@ -0,0 +1,30 @@ | |||
| package com.launchdarkly.sdk.server.datasources; | |||
|
|
|||
| import java.time.Duration; | |||
There was a problem hiding this comment.
This is probably fine in server, but we did recently make a PR to change one of these in internal or common. Because it isn't in the android API level that we use. But I wonder if we want to just not use java.time.Duration, or we just avoid it in the common libraries.
There was a problem hiding this comment.
This is only in the server SDK, which already uses java.time.Duration in 33 main source files on main, including the existing defaultFDv1FallbackTTL. The goodbye TTL comes from the internal lib as nullable Long millis, as of #273, and is converted to a Duration only here. As far as I can tell, lib/shared/common and lib/shared/internal have no java.time.Duration left. So "avoid it in the common libraries" seems to be the rule today, and this PR follows it. I'll leave it as is unless you'd like the server SDK to avoid it too.
There was a problem hiding this comment.
aside: I've seen so many bugs from code that disagreed about whether a Long was seconds or millis, I'm inclined to use Duration where we can. But I know we don't want to require desugaring in Android, so... well, I'll deal either way.
Co-Authored-By: Bee Klimt <bklimt@launchdarkly.com>
…rce configuration (#222) <!-- TERMAG_PR_BODY_BEGIN --> ## Update, 2026-12-01 - Rebased onto `feat/overrides`, which has `main` merged into it again. From `main` it gets the 7.19.0 to 7.19.2 releases, `java-sdk-internal` 1.14.0, and the FDv2 fix that leaves out an empty selector (#261). The v3.2.0-alpha.21 contract tests check that fix, so CI failed three FDv2 streaming tests without it. - The `@since` tags this PR adds now say 7.20.0, because 7.19.0 to 7.19.2 shipped from `main` without flag overrides. The change is in the existing commit "docs: Give the flag override API the version that will ship it". - `main` replaced the boolean FDv1 fallback argument of `FDv2SourceResult.changeSet` with an `FDv1Fallback` (#278). The override test data source passes `null`, as `main`'s own callers do. The change is in the first commit. - Verified with the v3.2.0-alpha.21 harness that CI runs, with `common` 2.6.0 and `internal` 1.15.0 published locally from `feat/overrides`: - every PR in the stack compiles, with Javadoc, at its own head; - the server unit tests pass at the top (2348, with the 72 existing skips); - the full v3 contract tests pass at the top (6457 tests ran). That includes the flag overrides suite and both flag listener suites. ## Update, 2026-11-13 - Rebased onto `feat/overrides`, which now includes #218 and #219 and has `main` merged into it. From `main` it gets the 7.18.0 release, CI on the latest v3 contract tests, flag change listener support in the contract test service, and the `java-sdk-internal` 1.12.1 and 1.12.2 fixes. A common 2.6.0 and internal 1.13.0 release from this branch needs those fixes. - New commit, "docs: Give the flag override API the version that will ship it". Java 7.18.0 was released from `main` without flag overrides, so the `@since` tags this PR adds now say 7.19.0, the next minor release. - Verified at the top of the stack, with `common` and `internal` published locally from `feat/overrides`: - every PR in the stack compiles, with Javadoc, at its own head; - the server unit tests pass (2285, with the 72 existing skips); - the full v3 contract tests pass (6321 tests). That includes the flag overrides suite, with the deleted-entry tests of launchdarkly/sdk-test-harness#599, and both flag listener suites. ## Summary This adds the override layer that the OVERRIDE specification describes: an override source supplies complete snapshots of flag and segment definitions to an override store, and an overlay at the store read boundary returns the store's entry for a key in preference to LaunchDarkly data. Evaluation, prerequisite and segment resolution, and the all-flags state all read through the overlay, so an override is a full definition that evaluates like any other. Overrides do not take part in the data system: they have no effect on initialization status, data availability, or data source status, and they are never written to a persistent store. Public surface, all marked experimental and subject to change: - `DataSystemBuilder.overrides(ComponentConfigurer<OverrideSource>)` and `DataSystemConfiguration.getOverrideSource()`. The option lives on the FDv2 data system builder only. An FDv1 data source configuration has no place to supply one. - `subsystems.OverrideSource` (start with a sink, close) and `subsystems.OverrideSink` (replace the whole layer with one snapshot). The SDK builds the source like any other component, starts it before the data source so its initial load completes during client construction, and closes it with the client; the sink stops accepting snapshots before the source is closed, and an exception from the source's `close` is logged while the rest of the shutdown proceeds. An offline client does not build or start the override source, and logs a warning that it does not. A source that cannot be built fails client construction the same way other invalid component configuration does. An exception from the source's `start` does not: the SDK logs it, closes the source, clears anything the source supplied before failing, and the client runs without overrides. Internals: - `OverrideLayer` holds marked shallow copies of the supplied entities in an immutable map that is swapped on each update. The source's objects are never modified. - `OverrideOverlayStore` implements the read boundary: per-key reads prefer the layer, enumeration is the union with override precedence, and a failure of the base store propagates, as it does without the overlay. - `OverrideSinkImpl` serializes snapshot application and fires the normal flag change notifications for every flag whose merged-view evaluation may have changed, using the dependency tracker over both the old and the new merged views so prerequisite and segment dependents are included. - The not-initialized short-circuit consults the layer first: a flag that the layer holds is served before the client has LaunchDarkly data, and any other flag returns the client-not-ready default as before. Before the store is initialized, the all-flags state contains only the flags that the layer holds, read from the layer rather than the merged store so that LaunchDarkly data in a store without an init marker stays out, and it logs once that it returned only override entries; with no override flags the state is invalid, as it is without a source. Without a source this state is empty, because the SDK reports no flags before the store is initialized, so the override flags only add to what it reports; overrides never remove a flag from the state. When the store fails to list its flags, the failure is logged as before; the state, invalid and empty without a source, then holds the override layer's flags and stays invalid (empty and invalid when the layer holds no flags), because a client-side SDK bootstrapped from it uses its flags whatever `$valid` says. The all-flags state presents an override-affected flag with `trackEvents` and `trackReason` false and no `debugEventsUntilDate`. The OVERRIDE specification's test vectors run as a unit test through the full client stack (value, variation index, and reason). The per-evaluation summary marker in the vectors is asserted by the events change that follows. This PR depends on the model and evaluator marking change (rlamb/overrides-java-model-marker) and is based on that branch; retarget it to feat/overrides once that branch merges. The existing file data source keeps its current behavior; this change does not touch its code paths. [SDK-3246](https://launchdarkly.atlassian.net/browse/SDK-3246) [SDK-3246]: https://launchdarkly.atlassian.net/browse/SDK-3246?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ ## Follow-ups from review - A LaunchDarkly change now notifies the flags whose overrides depend on it. The override layer keeps the dependency edges of its own entries, rebuilt on every replacement, and `DataSourceUpdatesImpl` expands each changed LaunchDarkly item through both its own tracker and the layer's until nothing new is reached, so an override that matches a LaunchDarkly segment or has a LaunchDarkly prerequisite is notified like the LaunchDarkly flags that depend on it. - `isFlagKnown` consults the override layer before the not-initialized short circuit, the same as evaluation does, so an override-only flag is known while the client is uninitialized. - When the evaluation of a flag throws during `allFlagsState`, the `EXCEPTION` result carries that flag's own override marking, so an overridden flag keeps its marked reason with event tracking off. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Overview** > Adds an **experimental flag/segment override** path for FDv2 clients so operators can force known definitions without changing initialization or data-source status. > > Configuration wires in `DataSystemBuilder.overrides()` with public `OverrideSource` / `OverrideSink` APIs. When configured, `FDv2DataSystem` builds an `OverrideLayer`, applies snapshots via `OverrideSinkImpl`, and exposes evaluations through `OverrideOverlayStore` (overrides win per key). The override source starts before the main data source; start/close failures are logged and the client can run without overrides. Offline mode skips the override source. > > Evaluation and client behavior are updated so override-backed flags work **before** the client is initialized (`isFlagKnown`, single-flag eval, `allFlagsState` with override-only/bootstrap semantics). Override-affected results carry marking in reasons and **disable** per-flag analytics fields in `FeatureFlagsState`. Flag-change notifications fan out across merged LaunchDarkly + override dependency graphs via `ExternalDependencies` on `DataSourceUpdatesImpl`. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 59f203e. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY --> <!-- TERMAG_PR_BODY_END --> <!-- termag: box=i-0575d1c54853058d7 project=java-core --> <sub>Opened from termag</sub>
🤖 I have created a release *beep* *boop* --- ## [7.20.0](launchdarkly-java-server-sdk-7.19.2...launchdarkly-java-server-sdk-7.20.0) (2026-12-03) ### Features * Add experimental support for file-based flag overrides ([5b3d8ea](5b3d8ea)) ### Bug Fixes * Keep flag file content out of the file data source's parse error messages ([5b3d8ea](5b3d8ea)) * Prevent YAML flag files that are parsed at the same time from returning each other's data ([5b3d8ea](5b3d8ea)) * Report a YAML flag file value that does not match its explicit tag as invalid data instead of an unexpected exception ([5b3d8ea](5b3d8ea)) * Use the server's FDv1 fallback TTL from the header and goodbye ([#278](#278)) ([e279d61](e279d61)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Overview** > This is a **Release Please** cut that publishes **launchdarkly-java-server-sdk 7.20.0**. The diff only bumps version metadata (`.release-please-manifest.json`, `gradle.properties`, and `Version.SDK_VERSION`) and adds the **7.20.0** section to `CHANGELOG.md`. > > That release (already landed on `main`) includes **experimental file-based flag overrides**, several **file/YAML `FileData` source** fixes (no flag content in parse errors, concurrent YAML isolation, clearer invalid-tag handling), and **FDv1 fallback TTL** behavior aligned with server headers/goodbye ([#278]). > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 6284b29. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY --> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>


Requirements
Related issues
Closes SDK-2987. Follows #265 and #273, the goodbye TTL parsing in
java-sdk-internal1.13.1. Spec: DATASYSTEM 1.6 (sdk-specs#251).Describe the solution you've provided
Previously the server SDK always used the jittered 1h default as the FDv1 fallback TTL. It now uses the TTL the server sends.
X-LD-FD-Fallback-TTLfrom the response that carriesX-LD-FD-Fallback, for both polling and streaming.goodbyethat hasprotocolFallbackTTLis now itself a fallback directive, and its TTL takes precedence over the header's.(0, 1h]is used as-is, with no jitter. A missing, malformed, zero, negative, or >1h TTL uses the jittered 1h default.FDv2SourceResult(experimental package) now carries a nullableFDv1Fallbackdirective, with a nullablegetTtl(), in place of theboolean fdv1Fallback.Implementation details
launchdarklyJavaSdkInternalfrom 1.13.0 to 1.13.1, which providesFDv2ActionGoodbye.getProtocolFallbackTTLMillis().HeaderConstants. A non-integer value gives a directive with a null TTL, which means the default.(0, 1h]check and the jitter live in one place,FDv2DataSource.fallbackTTL(Duration).InitializerOutcomenow carries the directive.false(file data source,TestDataV2,DataSourceSynchronizerAdapter) now passnull../gradlew test checkstyleMain checkstyleTestpasses inlib/sdk/server.Link to Devin session: https://app.devin.ai/sessions/cce64c67519f4babaa75176c06961c5e
Open in Devin Desktop: https://app.devin.ai/desktop/session/cce64c67519f4babaa75176c06961c5e?variant=devin
Requested by: @beekld
Note
Overview
Replaces the FDv1 fallback boolean on
FDv2SourceResultwith anFDv1Fallbackdirective (optional TTL) so the server can control how long FDv1 fallback runs before FDv2 is retried.X-LD-FD-Fallback-TTLis parsed alongsideX-LD-FD-Fallbackfor polling and streaming responses.goodbyeevents can carryprotocolFallbackTTL, which wins over header TTL when present. Valid server TTLs in (0, 1h] are used without jitter; missing, invalid, zero, negative, or >1h values fall back to the existing jittered default viaFDv2DataSource.fallbackTTL.Initializer and synchronizer orchestration propagate the full directive (including TTL refresh while already on FDv1). Integrations that never signaled fallback now pass
nullinstead offalse. Tests cover header/goodbye parsing, TTL validation, and end-to-end recovery timing.Reviewed by Cursor Bugbot for commit 5bae068. Bugbot is set up for automated code reviews on this repo. Configure here.